// pages/insuranceDetails/insuranceDetails.js
var app = getApp();
const constant = require('../../constant');
const WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    goods_id: 0,
    baseinfo: [],
    goods_article: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goods_id: options.goods_id
    })
    this.getproductinfo();
    //this.getproductarticle();
  },
  //获取保险详情
  getproductinfo() {
    let that = this;
    app.get('Goods/getproductinfo', {
      goods_id: this.data.goods_id
    }, function (res) {
      if (res.code == 200 && res.data != null) {
        res.data.goods_img = constant.config.host + res.data.goods_img;
        that.setData({
          baseinfo: res.data,
        })
        WxParse.wxParse('productinfo', 'html', that.data.baseinfo.content, that, 5);
        
      }
    })
  },
  //获取投保攻略
  getproductarticle() {
    let that = this;
    app.get('Goods/getproductarticle', {
      goods_id: this.data.goods_id
    }, function (res) {
      if (res.code == 200 && res.data != null) {
        that.setData({
          goods_article: res.data,
        })
        WxParse.wxParse('article', 'html', that.data.goods_article.content, that, 5);

      }
    })
  },
  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  //点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  toBuy() {
    app.checkLoginstatus();

    var payInfo = [], goodsInfo = {};
    goodsInfo['goods_id'] = this.data.baseinfo.goods_id;
    goodsInfo['title'] = this.data.baseinfo.title;
    goodsInfo['goods_img'] = this.data.baseinfo.goods_img;
    goodsInfo['cost_price'] = this.data.baseinfo.cost_price;
    goodsInfo['price'] = this.data.baseinfo.price;
    goodsInfo['freight_fee'] = this.data.baseinfo.freight_fee;
    goodsInfo['goods_type'] = this.data.baseinfo.cat_id;
    goodsInfo['total_stock'] = this.data.baseinfo.total_stock;
    goodsInfo['num'] = '1';
    payInfo = payInfo.concat(goodsInfo);
    wx.setStorageSync('payinfo', payInfo)
    wx.navigateTo({
      url: '../previewGoodsOrder/previewGoodsOrder',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})